home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Sort Function
- Date: Mon, 01 Apr 96 14:17:44 GMT
- Organization: none
- Message-ID: <828368264snz@genesis.demon.co.uk>
- References: <4jmq99$cqi@freenet-news.carleton.ca>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4jmq99$cqi@freenet-news.carleton.ca>
- aq436@FreeNet.Carleton.CA "Jerry Boyd" writes:
-
- >How would I WRITE a function (called sort3) that would
- >sort three integers (in assending order) by using pointers
- >and NOT arrays?
-
- Define your function interface i.e. in what form you want the data passed
- to the function and in what form you want the results. For example if
- you want to pass 3 pointer arguments you could write something along the
- lines of:
-
- void sort3(int *p1, int *p2, int *p3)
-
- {
- if (*p1 > *p2)
- swapint(p1, p2);
-
- if (*p2 > *p3) {
- swapint(p2, p3);
-
- if (*p1 > *p2)
- swapint(p1, p2);
- }
- }
-
- where I leave it up to you to implement swapint().
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-